package isi.webservice.bank;

/*
 * Materiale didattico per corso sulle Applicazioni Internet 
 * 
 * Copyright (c) 2005-2008 Link.it srl (http://link.it). All rights reserved.
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

/**
 * @author Lorenzo Nardi (nardi80@gmail.com)
 */

import javax.xml.namespace.QName;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPBodyElement;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPMessage;
import javax.xml.ws.Provider;
import javax.xml.ws.Service;
import javax.xml.ws.ServiceMode;
import javax.xml.ws.WebServiceException;
import javax.xml.ws.WebServiceProvider;


@ServiceMode(value=Service.Mode.MESSAGE)

@WebServiceProvider(serviceName = "BankService",
		portName = "Bank",
		targetNamespace = "http://www.bank.com/ns")
		
public class Sportello implements Provider<SOAPMessage>{
			
	public SOAPMessage invoke(SOAPMessage req){
		
		SOAPMessage res = null;
		try{
			MessageFactory msgFac = MessageFactory.newInstance();
			res = msgFac.createMessage();
			SOAPBodyElement saldoResponse = res.getSOAPBody().addBodyElement(new QName("http://www.bank.com/ns","saldoResponse","bns"));
			SOAPElement saldo = saldoResponse.addChildElement(new QName("http://www.bank.com/ns","saldo","bns"));
			saldo.setValue("10");
		}
		catch(Exception e){
			System.out.println("Errore SOAP: " + e);
			throw new WebServiceException(e);
		}
		
		return res;
	}
}
